package com.jjclub.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jjclub.entity.JjclubMenu;
import com.jjclub.mapper.JjclubMenuMapper;
import com.jjclub.service.JjclubUserService;
import com.mysql.cj.xdevapi.JsonArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Classname JjclubUserServiceImpl
 * @Description TODO
 * @Date 2019/11/8 9:56
 * @Created by jq
 */
@Service
public class JjclubUserServiceImpl implements JjclubUserService {

    @Autowired
    private JjclubMenuMapper jjclubMenuMapper;


    @Override
    public List<JjclubMenu> getUsersMenuByLoginid(String loginid) {
        List<JjclubMenu> jjclubMenus = jjclubMenuMapper.findAllMenuByUserid(loginid);
        return jjclubMenus;
    }

    @Override
    public List<JjclubMenu> getAllMenusByLoginid(String loginid) {
        List<JjclubMenu> jjclubMenus = jjclubMenuMapper.findAllMenuByUserid(loginid);
        for (JjclubMenu jjclubMenu :jjclubMenus){
            List<JjclubMenu> jjclubMenus1 = jjclubMenuMapper.findChildrenMenusByParentid(jjclubMenu.getId(),loginid);
            for (JjclubMenu jjclubMenu1:jjclubMenus1){
                List<JjclubMenu> jjclubMenus2 = jjclubMenuMapper.findChildrenMenusByParentid(jjclubMenu1.getId(),loginid);
                jjclubMenu1.setChildren(jjclubMenus2);
            }
            jjclubMenu.setChildren(jjclubMenus1);
        }
        return jjclubMenus;
    }
}
